
#ifndef _ZEROCOPY_H_
#define _ZEROCOPY_H_

using namespace std;

#include <fastdds/dds/topic/Topic.hpp>

#include <fastdds/dds/domain/DomainParticipant.hpp>
#include <fastdds/dds/publisher/Publisher.hpp>
#include <fastdds/dds/subscriber/Subscriber.hpp>
#include <fastdds/dds/topic/Topic.hpp>
#include <fastdds/dds/publisher/DataWriter.hpp>
#include <fastdds/dds/subscriber/DataReader.hpp>
#include <fastdds/dds/publisher/DataWriterListener.hpp>
#include <fastdds/dds/subscriber/DataReaderListener.hpp>

#include "smallData.h"
#include "mediumData.h"
#include "bigData.h"
#include "messData.h"
#include "smallDataPubSubTypes.h"
#include "mediumDataPubSubTypes.h"
#include "bigDataPubSubTypes.h"
#include "messDataPubSubTypes.h"

#include "myLog.h"

#include <chrono>
#include <atomic>

#include <sys/time.h>                                                                                           
#include <unistd.h>

#define INIT_PUB    1
#define INIT_SUB    2

class zeroCopyPublisher final
{

public:
    zeroCopyPublisher();
    ~zeroCopyPublisher();

    //!Initialize
    bool init(
            int transport,
            eprosima::fastrtps::ReliabilityQosPolicyKind kind,
            int data_size,
            int tick_time,
            const std::string& topicName,
            int domain,
			int loan,
            int size);

    void run();

    //!Publish a sample
    bool publish();

    void setDdsAttribute(const std::string &topicName, const std::string &participantName, const uint32_t domainId);
private:

	std::chrono::time_point<std::chrono::system_clock> m_testStartTime;

	bool m_bBenchmarkFinished;

	int m_iTestSize;

	int m_iTickTime;

	std::atomic_uint m_iCount;

	int m_iSize;
	
	int m_iLoan;

	int* m_vSamples;

	int m_iSamplesSize;
	//测试次数用总大小除以每个样本的大小
	int m_iSamplesCount;

	messData m_Hello;

	smallData m_HelloSmall;

	mediumData m_HelloMedium;

	bigData m_HelloBig;

	eprosima::fastdds::dds::DomainParticipant* mp_participant;

	eprosima::fastdds::dds::Publisher* mp_publisher;

	eprosima::fastdds::dds::DataWriter* mp_writer;

	eprosima::fastdds::dds::Subscriber* mp_subscriber;

	eprosima::fastdds::dds::DataReader* mp_reader;

	eprosima::fastdds::dds::Topic* mp_topic_pub;

	eprosima::fastdds::dds::Topic* mp_topic_sub;

	class PubListener : public eprosima::fastdds::dds::DataWriterListener
	{
	public:

			PubListener()
			{
			}

			PubListener(
					zeroCopyPublisher* parent);

			~PubListener() override
			{
			}

			void on_publication_matched(
					eprosima::fastdds::dds::DataWriter* writer,
					const eprosima::fastdds::dds::PublicationMatchedStatus& info) override;

			zeroCopyPublisher* mParent;

			int matched_;

	} m_pubListener;

	eprosima::fastdds::dds::TypeSupport m_type;

	eprosima::fastdds::dds::TypeSupport m_typeSmall;

	eprosima::fastdds::dds::TypeSupport m_typeMedium;

	eprosima::fastdds::dds::TypeSupport m_typeBig;

	void runThread();
};



#endif